<?php

namespace app\common\model\mysql;

use think\Model;

class SMember extends Model
{
    /**
     * @var mixed
     */
    private $id;

    public function getMemberByOpenid($unionid){
        if(empty($unionid)){
            return false;
        }
        $where = [
            "wechat_unionid" =>$unionid,
        ];
        $result = $this->where($where)->find();
        return $result;
    }

    // 添加用户
    public function addMember($data){
        $this->save($data);
        return $this->id;
    }

    // 修改用户
    public function updateMember($id,$data){
        $id = intval($id);
        if(empty($id) || empty($data) || !is_array($data)){
            return false;
        }
        $where = [
            "member_id"=>$id,
        ];
        return $this->where($where)->save($data);
    }

    /**
     * 根据id获取用户信息
     * @param $memberId
     * @return SMember|array|false|mixed|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getMemberIdData($where,$field = "*"){
        $result = $this->where($where)->field($field)->find();
        return $result;
    }
}
